package com.mobiusws.reports.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import com.mobiusws.reports.action.DailyFraudSummaryAction;
import com.mobiusws.reports.action.MenuTestAction;
import com.mobiusws.reports.model.CallType;
import com.mobiusws.reports.model.DailyFraudSummary;
import com.mobiusws.reports.model.LoginInfo;
import com.mobiusws.reports.model.MenuItem;
import com.mobiusws.util.JsonUtil;

@Repository("menuTestDao")
public class MenuTestDao {
	@Resource
	private JdbcTemplate dbxJdbc;
	@Resource
	private JdbcTemplate coreJdbc;

	@SuppressWarnings("unchecked")
	public List<MenuItem> getMenuItem(MenuTestAction action) {

		String sql = "select * from menu";
		List<MenuItem> list = dbxJdbc.query(sql, new Object[] {},
				new RowMapper() {
					@Override
					public Object mapRow(ResultSet rs, int rowNum)
							throws SQLException {
						MenuItem item = new MenuItem();
						item.setId(rs.getInt("id"));
						item.setParentId(rs.getInt("parent_id"));
						item.setText(rs.getString("name"));
						item.setHrefTarget(rs.getString("url"));
						item.setLeaf(rs.getInt("is_leaf") == 1);
						return item;
					}
				});
		//testList(list);
		return list;
	}

	private void testList(List<MenuItem> list) {
		for (MenuItem item : list) {
			System.out.printf("%d, %d, %s, %s, %s", item.getId(),
					item.getParentId(), item.getText(), item.getHrefTarget(),
					item.isLeaf());
			System.out.println();
		}
	}
}
